package com.yaoweigroup.community.adapter;

import java.util.List;

import com.yaoweigroup.community.R;
import com.yaoweigroup.community.enity.HomeIcon;
import com.yaoweigroup.community.enity.TypeIcon;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AppsAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<HomeIcon> items;

	public AppsAdapter(Context context, List<HomeIcon> items) {
		this.items = items;
		inflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = this.inflater.inflate(R.layout.adapter_app_item_view,
					null);
			holder.tv = (TextView) convertView.findViewById(R.id.item_tv);
			holder.icon_iv = (ImageView) convertView.findViewById(R.id.icon_iv);
			holder.add_iv = (ImageView) convertView.findViewById(R.id.add_iv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv.setText(items.get(position).getTypeName());
		holder.icon_iv.setImageResource(items.get(position).getResId());
		boolean isSelect = items.get(position).isSelect();
		if (isSelect) {
			holder.add_iv.setImageResource(R.drawable.add_ok);
		} else {
			holder.add_iv.setImageResource(R.drawable.add_cancel);
		}
		return convertView;
	}

	private class ViewHolder {
		TextView tv;
		ImageView icon_iv;
		ImageView add_iv;
	}

	public void setDataChange(List<HomeIcon> list) {

		this.items = list;
		notifyDataSetChanged();
	}

}
